package concurrent.chapter8;

/**
 * Future ->代表的是未来的一个凭据
 * Future ->将你的调用逻辑进行了隔离
 * FutureService ->桥接Future和FutureTask
 */
public class SyncInvoker {
    public static void main(String[] args) throws InterruptedException {
        //String result = get();
        //System.out.println(result);

        FutureService futureService = new FutureService();
        Future<String> future = futureService.submit(() -> {
            try {
                Thread.sleep(7_000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "FINISH";
        }, System.out::println);
        System.out.println("======");
        System.out.println("do other thing.");
        Thread.sleep(5000);
        System.out.println("======");
        System.out.println(future.get());
    }

    private static String get() throws InterruptedException {
        Thread.sleep(4_000L);
        return "FINISH";
    }
}
